﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Payroll.BusinessLogic;
using PayrollHR.Web;

namespace PayrollHR.Administration.Modules
{
    public partial class ListCustomerType : BasePayrollAdministrationUserControl
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                Bind();
            }
        }
        private void Bind()
        {
            string customertype = ctrCustomerTypeSearch.customerTypeSearch;
            gvCustomerType.DataSource = this.CustomerService.GetCustomerType(customertype);
            gvCustomerType.DataBind();
        }

        protected void btnDelete_Click(object sender, EventArgs e)
        {
            if (Page.IsValid)
            {
                try
                {
                    List<int> lCustomerType = new List<int> { };
                    foreach (GridViewRow row in gvCustomerType.Rows)
                    {
                        CheckBox cbCustomerInfo = row.FindControl("cbCustomerInfo") as CheckBox;
                        HiddenField hfCustomerID = row.FindControl("hfCustomerID") as HiddenField;
                        int CustomerID = int.Parse(hfCustomerID.Value);
                        if (cbCustomerInfo.Checked)
                        {
                            lCustomerType.Add(CustomerID);
                        }
                     
                    }
                    if (lCustomerType.Count > 0)
                    {
                        foreach (int icheck in lCustomerType)
                        {
                            this.CustomerService.DelateCutomerType(icheck);
                        }
                        Bind();
                    }
                }
                catch (Exception ex)
                {
                    throw ex;
                }
            }
        }

        protected void SearchButton_Click(object sender, EventArgs e)
        {
            Bind();
        }
    }
}